/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/** *****************************************************************************************************
 * \file     Icu_Ip_Xtrg.h                                                                              *
 * \brief    This file mainly contains the definition of xtrg register operation                        *
 *                                                                                                      *
 * <table>                                                                                              *
 * <tr><th>Date           <th>Version                                                                   *
 * <tr><td>2023/08/18     <td>1.0.0                               *
 * </table>                                                                                             *
 *******************************************************************************************************/
#ifndef ICU_IP_XTRG_H
#define ICU_IP_XTRG_H

#ifdef __cplusplus
extern "C" {
#endif

/********************************************************************************************************
 *                                      Include header files                                            *
 *******************************************************************************************************/
/* icu data types file */
#include "Icu_Types.h"
/* mcal types file */
#include "Mcal.h"
/* icu config file */
#include "Icu_Cfg.h"
/* icu ip level file */
#include "Icu_Ip.h"

/********************************************************************************************************
 *                                         Macro definition                                             *
 *******************************************************************************************************/
/* etimer module base address macro */
#define APBMUX_XTRG1_BASE               (0xF8170000UL)
#define APBMUX_XTRG2_BASE               (0xF8180000UL)
/* etimer hardware information */
#define XTRG_MODULE_NUMBER             (0x02U)

#if (STD_ON == ICU_XTRG_CHANNEL_ENABLE)
/********************************************************************************************************
 *                                         Function definition                                          *
 *******************************************************************************************************/
/** *****************************************************************************************************
 * \brief This function initializes the xtrg channel and set the xtrg module
 *        registers
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_XtrgChannelInit(
 *                              const Icu_XtrgChannelConfigType* xtrgChanConfigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : channelConfigPtr - pointer to xtrg channel configuration
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function initializes the channel and set the etimer
 *                      hardware registers
 * \endverbatim
 * Traceability       : SWSR_ICU_034 SWSR_ICU_035 SWSR_ICU_037
 *                      SW_SM006
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgChannelInit(const Icu_XtrgChannelConfigType* xtrgChanConfigPtr);

#if (STD_ON == ICU_DEINIT_API) || defined(LOWPOWER_SUPPORT_SUSPEND_RESUME)
/** *****************************************************************************************************
 * \brief This function de-initializes the channel and set the xtrg hardware
 *        registers
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_XtrgChannelDeInit(
 *                                                  const Icu_XtrgChannelConfigType* xtrgChanConfigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgChanConfigPtr - pointer to xtrg channel configuration
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : This function de-initializes the channel and set the etimer
 *                      hardware registers
 * \endverbatim
 * Traceability       : SWSR_ICU_034 SWSR_ICU_035 SWSR_ICU_037
 *                      SW_SM006
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgChannelDeInit(const Icu_XtrgChannelConfigType* xtrgChanConfigPtr);
#endif /* STD_ON == ICU_DEINIT_API || defined(LOWPOWER_SUPPORT_SUSPEND_RESUME) */

/** *****************************************************************************************************
 * \brief This function turn On the xtrg capture channel
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_TurnOnCapture(
 *                                              Icu_XtrgHwChannel xtrgChan)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgChan - xtrg cpt cchannel module
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function turn off the xtrg capture channel
 * \endverbatim
 * Traceability       : None
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgTurnOnCapture(Icu_XtrgHwModule xtrgModule, Icu_XtrgHwChannel xtrgChan);


/** *****************************************************************************************************
 * \brief This function turn off the xtrg capture channel
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_TurnOffCapture(
 *                                              Icu_XtrgHwChannel xtrgChan)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgChan - xtrg cpt cchannel module
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function turn off the xtrg capture channel
 * \endverbatim
 * Traceability       : None
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgTurnOffCapture(Icu_XtrgHwModule xtrgModule, Icu_XtrgHwChannel xtrgChan);

/** *****************************************************************************************************
 * \brief This function sets the xtrg active edge information
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_XtrgSetActCondition(
 *                          Icu_XtrgHwChannel xtrgChan,
 *                          Icu_ActivationType activation,
 *                          boolean runSta)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgChan - xtrg cpt hardware module
 *                      activation - activation edge information
 *                      runSta - channel running status
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function sets the xtrg active edge information
 * \endverbatim
 * Traceability       : SWSR_ICU_055
 *                      SW_SM006
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgSetActCondition(Icu_XtrgHwModule xtrgModule, Icu_XtrgHwChannel xtrgChan, Icu_ActivationType activation, boolean runSta);

#if (STD_ON == ICU_GET_INPUTSTATE_API)
/** *****************************************************************************************************
 * \brief This function gets input status
 *
 * \verbatim
 * Syntax             : Icu_InputStateType Icu_Ip_XtrgGetInputState(
 *                              Icu_HwModule tmrModule, Icu_HwChannel hwChannel)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : tmrModule - etimer hardware module
 *                      hwChannel - etimer hardware channel
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The input status in sigmeasurement mode
 *
 * Description        : This function gets input status
 * \endverbatim
 * Traceability       : SWSR_ICU_069 SWSR_ICU_071 SWSR_ICU_072 SWSR_ICU_073
 *******************************************************************************************************/
Icu_InputStateType Icu_Ip_XtrgGetInputState(uint8 xtrgLogCh);
#endif /* STD_ON == ICU_GET_INPUTSTATE_API */

#if (STD_ON == ICU_SIGNALMEASUREMENT_API)
/** *****************************************************************************************************
 * \brief This function starts capture in signal measurement mode with xtrg
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_XtrgStartSigMeament(
 *                              uint8 xtrgLogCh, Icu_XtrgHwChannel xtrgChan)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgLogCh - xtrg logic channel index
 *                      xtrgChan - xtrg hardware capture module
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function starts capture in signal measurement mode
 *                      with xtrg capture module
 * \endverbatim
 * Traceability       : SWSR_ICU_153 SWSR_ICU_155
 *                      SW_SM006
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgStartSigMeament(Icu_XtrgHwModule xtrgModule, uint8 xtrgLogCh, Icu_XtrgHwChannel xtrgChan);

/** *****************************************************************************************************
 * \brief This function stops capture in signal measurement mode with xtrg
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_XtrgStopSigMeament(
 *                              uint8 xtrgLogCh, Icu_XtrgHwChannel xtrgChan)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgLogCh - xtrg logic channel index
 *                      xtrgChan - xtrg hardware capture module
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function stops capture in signal measurement mode
 *                      with xtrg capture module
 * \endverbatim
 * Traceability       : SWSR_ICU_153 SWSR_ICU_155
 *                      SW_SM006
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgStopSigMeament(Icu_XtrgHwModule xtrgModule, uint8 xtrgLogCh, Icu_XtrgHwChannel xtrgChan);

/** *****************************************************************************************************
 * \brief This function calculates the signal time in sigmeasurement mode
 *
 * \verbatim
 * Syntax             : void Icu_Ip_XtrgSigMeaIrq(
 *                              const Icu_ChannelConfigType* channelConfigPtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgLogCh - xtrg logic channel index
 *                      xtrgChan - xtrg hardware capture module
 *                      sigMeaType - signal measurement types
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : None
 *
 * Description        : This function calculates the signal time in
 *                      sigmeasurement mode
 * \endverbatim
 * Traceability       : None
 *******************************************************************************************************/
void Icu_Ip_XtrgSigMeaIrq(Icu_XtrgHwModule xtrgModule, uint8 xtrgLogCh, Icu_XtrgHwChannel xtrgChan, Icu_SignalMeasurementPropertyType sigMeaType);

#if (STD_ON == ICU_GET_DUTYCYCLE_VALUES_API)
/** *****************************************************************************************************
 * \brief This function gets dutycycle value in signal measurement mode
 *
 * \verbatim
 * Syntax             : Std_ReturnType Icu_Ip_XtrgGetDutyCycle(
 *                              uint8 xtrgLogCh,
 *                              Icu_DutyCycleType* dutyCyclePtr)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgLogCh - xtrg logic channel index
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : dutyCyclePtr - pointer to a buffer where the results
 *
 * Return value       : The result status
 *
 * Description        : This function gets dutycycle value in signal measurement
 *                      mode
 * \endverbatim
 * Traceability       : SWSR_ICU_180 SWSR_ICU_181 SWSR_ICU_182 SWSR_ICU_183
 *                      SW_SM006
 *******************************************************************************************************/
Std_ReturnType Icu_Ip_XtrgGetDutyCycle(uint8 xtrgLogCh, Icu_DutyCycleType* dutyCyclePtr);
#endif /* STD_ON == ICU_GET_DUTYCYCLE_VALUES_API */

#if (STD_ON == ICU_GET_TIMEELAPSED_API)
/** *****************************************************************************************************
 * \brief This function gets signal time in signal measurement mode
 *
 * \verbatim
 * Syntax             : Icu_ValueType Icu_Ip_XtrgGetTimeElapsed(
 *                              uint8 xtrgLogCh)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : xtrgLogCh - xtrg logic channel index
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The signal time value
 *
 * Description        : This function gets signal time in signal measurement
 *                      mode
 * \endverbatim
 * Traceability       : SWSR_ICU_168 SWSR_ICU_169 SWSR_ICU_170 SWSR_ICU_171
 *                      SWSR_ICU_172 SWSR_ICU_173
 *******************************************************************************************************/
Icu_ValueType Icu_Ip_XtrgGetTimeElapsed(uint8 xtrgLogCh);
#endif /* STD_ON == ICU_GET_TIMEELAPSED_API */
#endif /* STD_ON == ICU_SIGNALMEASUREMENT_API */

/** *****************************************************************************************************
 * \brief This function gets the interrupt status_0
 *
 * \verbatim
 * Syntax             : uint32 Icu_Ip_XtrgGetIntSta0(Icu_XtrgHwModule xtrgModule)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The interrupt status0
 *
 * Description        : This function gets the interrupt status
 * \endverbatim
 * Traceability       : SWSR_ICU_190
 *******************************************************************************************************/
uint32 Icu_Ip_XtrgGetIntSta0(Icu_XtrgHwModule xtrgModule);

/** *****************************************************************************************************
 * \brief This function gets the interrupt status_1
 *
 * \verbatim
 * Syntax             : uint32 Icu_Ip_GetInterrupt(Icu_XtrgHwModule xtrgModule)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : None
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The interrupt status1
 *
 * Description        : This function gets the interrupt status
 * \endverbatim
 * Traceability       : SWSR_ICU_190
 *******************************************************************************************************/
uint32 Icu_Ip_XtrgGetIntSta1(Icu_XtrgHwModule xtrgModule);

/** *****************************************************************************************************
 * \brief This function clear the interrupt status
 *
 * \verbatim
 * Syntax             : void Icu_Ip_XtrgClrInterrupt(Icu_XtrgHwModule xtrgModule, Icu_XtrgHwChannel xtrgChan)
 *
 * Service ID[hex]    : None
 *
 * Sync/Async         : Synchronous
 *
 * Reentrancy         : None
 *
 * Parameters (in)    : tmrModule - etimer hardware module
 *                      hwChannel - etimer hardware channel
 *
 * Parameters (inout) : None
 *
 * Parameters (out)   : None
 *
 * Return value       : The setting result
 *
 * Description        : This function clear the interrupt status
 * \endverbatim
 * Traceability       : SWSR_ICU_190
 *******************************************************************************************************/
void Icu_Ip_XtrgClrInterrupt(Icu_XtrgHwModule xtrgModule, Icu_XtrgHwChannel xtrgChan);

#endif /* STD_ON == ICU_XTRG_CHANNEL_ENABLE */

#ifdef __cplusplus
}
#endif

#endif /* ICU_IP_XTRG_H */
/* End of file */
